package org.example;

public class Main {
    public static void main(String[] args) {

        TreeNode treeNode = new TreeNode(3);

        treeNode.left = new TreeNode(9);
        treeNode.right = new TreeNode(20);
        treeNode.right.left = new TreeNode(15);
        treeNode.right.right = new TreeNode(7);

        TreeNode treeNode1 = mirrorTree(treeNode);
        System.out.println(treeNode1);

    }

    public static TreeNode mirrorTree(TreeNode root) {
        //如果根节点为空，则返回空
        if(root == null) {
            return null;
        }
        //将根节点的左子树赋值给临时变量tmp
        TreeNode tmp = root.left;
        //将根节点的右子树赋值给根节点的左子树
        root.left = mirrorTree(root.right);
        //将临时变量tmp的值赋值给根节点的右子树
        root.right = mirrorTree(tmp);
        //返回根节点
        return root;
    }

}